// Lindsay Gilmour
// Adam Lusch
// Dan Niceswanger
//
// Computer Graphics Project 1:
// Asteroids!
// A Tribute

#include "Particle.h"

Particle::Particle(const b2Vec2& pos, const b2Vec2& vel)
{
	ttl = 20;
	position = pos;
	velocity = vel;
	alpha = 1.0f;
	
	displayList = glGenLists(1);
	
	glNewList(displayList, GL_COMPILE);

	glBegin(GL_LINE_LOOP);
		glVertex2f(0.0f, 0.1f);
		glVertex2f(-0.1f, 0.0f);
		glVertex2f(0.0f, -0.1f);
		glVertex2f(0.1f, 0.0f);
	glEnd();
	
	glEndList();
}

Particle::~Particle()
{
	glDeleteLists(displayList, 1);
}

void Particle::draw()
{
	glPushMatrix();
	
	glTranslatef(position.x, position.y, 0.0f);
	
	glColor4f(0.6f, 0.8f, 0.6f, alpha);
	glCallList(displayList);
	
	glPopMatrix();
	
	alpha -= 1.0 / ttl;
	--ttl;
	
	position += velocity;
}

int32 Particle::getTTL() const
{
	return ttl;
}
